package com.local.controller.index;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.cz073586.tools.util.Log4jUtil;
import com.local.model.LocalMemberFinance;
import com.local.model.LocalRotaUser;
import com.local.model.LocalStation;
import com.local.page.LocalMemberFinancePage;
import com.local.page.LocalRotaUserPage;
import com.local.page.LocalStationPage;
import com.local.service.face.LocalMemberFinanceService;
import com.local.service.face.LocalRotaService;
import com.local.service.face.LocalRotaUserService;
import com.local.service.face.LocalStationService;
import com.qianhai.common.constants.CommonContans;
import com.qianhai.common.controller.BaseController;
import com.qianhai.common.entity.LoginUserInfo;
import com.qianhai.common.utils.Tools;

/**
 * 类描述:这里是类描述
 * 
 * @ClassName: TestController
 * @author Administrator
 * @date 2015年4月23日 下午3:25:18
 */
@RestController
@RequestMapping(value = "/index/jump", method = RequestMethod.POST)
public class WorkTransitionController extends BaseController
{
	
	protected Log4jUtil log = Log4jUtil.getLog4j(this.getClass());
	
	@Autowired
	private LocalRotaService localRotaService;
	@Autowired
	private LocalRotaUserService localRotaUserService;
	@Autowired
	private LocalStationService localStationService;
	
	
	
	
	@RequestMapping(value = "/loginJump.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap loginJump()
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			LoginUserInfo login=this.getLoginUser();
			if(!Tools.isEmpty(login)){
				resultMap.put(CommonContans.STRUTS_DATA, localRotaUserService.queryStationByUser(login.getUuid()));
			}
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
			
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	@RequestMapping(value = "/roteUserToStation.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap roteUserToStation(@RequestBody LocalRotaUserPage<LocalRotaUser> pageInfo){
		ModelMap resultMap = new ModelMap();
		
		try
		{
			localRotaUserService.roteUserToStationPage(pageInfo);
			resultMap.put(CommonContans.STRUTS_DATA, pageInfo);
			resultMap.put(CommonContans.STRUTS_RESULT,CommonContans.STRUTS_SUCCESS);
			
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	@RequestMapping(value = "/queryStationOther.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryStationOther(@RequestBody LocalStationPage<LocalStation> page)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			List<LocalStation> list = localStationService.queryByPage(page);
			page.setData(list);
			resultMap.put(CommonContans.STRUTS_DATA, page);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	
	@RequestMapping(value = "/blindUserToStation.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap blindUserToStation(@RequestBody LocalRotaUser localRotaUser){
		ModelMap resultMap = new ModelMap();
		
		try
		{
			if(!Tools.isEmpty(localRotaUser)&&!Tools.isEmpty(localRotaUser.getUuid())){
				localRotaUserService.blindUserToStation(localRotaUser);
				resultMap.put(CommonContans.STRUTS_RESULT,CommonContans.STRUTS_SUCCESS);
			}else{
				resultMap.put(CommonContans.STRUTS_RESULT,CommonContans.STRUTS_ERROR);
			}
			
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	
	@RequestMapping(value = "/blindUserAndStation.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap blindUserAndStation(@RequestBody LocalRotaUser localRotaUser){
		ModelMap resultMap = new ModelMap();
		try
		{
			if(!Tools.isEmpty(localRotaUser)&&!Tools.isEmpty(localRotaUser.getRotaUuid())&&!Tools.isEmpty(localRotaUser.getUserId())&&!Tools.isEmpty(localRotaUser.getStationUuid())){
				localRotaUserService.blindUserAndStation(localRotaUser);
				resultMap.put(CommonContans.STRUTS_RESULT,CommonContans.STRUTS_SUCCESS);
			}else{
				resultMap.put(CommonContans.STRUTS_RESULT,CommonContans.STRUTS_ERROR);
			}
			
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	
	@RequestMapping(value = "/queryRotaUserStationByUuid.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryRotaUserStationByUuid(@RequestBody LocalRotaUser localRotaUser){
		ModelMap resultMap = new ModelMap();
		try
		{
			if(!Tools.isEmpty(localRotaUser)&&!Tools.isEmpty(localRotaUser.getUuid())){
				resultMap.put(CommonContans.STRUTS_DATA, localRotaUserService.queryRotaUserStationByUuid(localRotaUser.getUuid()));
				resultMap.put(CommonContans.STRUTS_RESULT,CommonContans.STRUTS_SUCCESS);
			}else{
				resultMap.put(CommonContans.STRUTS_RESULT,CommonContans.STRUTS_ERROR);
			}
			
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	@RequestMapping(value = "/delRotaUserStationByUuid.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap delRotaUserStationByUuid(@RequestBody LocalRotaUser localRotaUser){
		ModelMap resultMap = new ModelMap();
		try
		{
			if(!Tools.isEmpty(localRotaUser)&&!Tools.isEmpty(localRotaUser.getUuid())){
				localRotaUserService.delRotaUserStationByUuid(localRotaUser.getUuid());
				resultMap.put(CommonContans.STRUTS_RESULT,CommonContans.STRUTS_SUCCESS);
			}else{
				resultMap.put(CommonContans.STRUTS_RESULT,CommonContans.STRUTS_ERROR);
			}
			
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
}
